using Gtk;
using PArticulo;
using System;

public partial class MainWindow : Gtk.Window
{
	private int paginasCreadas= 0;
	
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		notebook.SwitchPage += delegate 
		{
			deleteAction.Sensitive= notebook.CurrentPage > -1;
		};
		
		notebook.PageRemoved += delegate
		{
			deleteAction.Sensitive= notebook.CurrentPage > -1;
		};
		
		deleteAction.Sensitive= notebook.CurrentPage > -1;
		
		ArticuloAction.Activated += delegate 
		{
			addPage("SELECT * FROM articulo");
		};
		CategoriaAction.Activated += delegate 
		{
			addPage("SELECT * FROM categoria");
		};
	}
	
	private void addPage(string consulta) 
	{
		DBVisor dbVisor = new DBVisor(consulta);
		dbVisor.Visible= true;
		
		HBox hBox= new HBox();
		Label label= new Label("Página nueva "+ ++paginasCreadas);
		label.Visible= true;
		hBox.Add(label);

		Button button= new Button();
		button.Image= Image.NewFromIconName(Stock.Close, IconSize.Button);
		button.Visible= true;
		hBox.Add(button);
		
		button.Clicked += delegate 
		{
			notebook.Remove(dbVisor);
		};
		
		notebook.CurrentPage= notebook.AppendPage(dbVisor, hBox);
		
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}
